09. Write Your First Test Continued

L5 A06 Write Your First Test (No TDD) Part 2

Step 1: Practice Test Driven Development (TDD)

Now you can do the short Test Driven Development (TDD) exercise shown in the video:

  1. Write some tests for the buggy edge cases; follow TDD as shown in the video:
    • If there is an empty list (emptyList()), then both percentages should be 0f.
    • If there was an error loading tasks, the list will be null, then both percentages should be 0f.
  2. Confirm these tests fail.

When following TDD, you'll write the tests first and then update the actual code.

  1. Update getActiveAndCompletedStats to remove the bug where the wrong values are returned on an empty list and error.
  2. Confirm your tests pass.

Test Driven Development

To learn more about Test Driven Development in Android, you can watch Test-Driven Development on Android with the Android Testing Support Library (Google I/O '17) (note the Android Testing Support Library has been replaced by AndroidX Test which you'll learn about later).